package org.example.back.mapper.user;

import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.example.back.entity.user.UserMeal;
import org.example.back.entity.user.UserMealFood;

import java.time.LocalDate;
import java.util.List;
import java.util.Map;

@Mapper
public interface UserMealMapper {
    int insertUserMeal(UserMeal userMeal);


    int insertUserMealFood(UserMealFood food);


    List<UserMeal> findMealsByDate(Integer userId, LocalDate date);


    Map<String, Object> getDailyNutritionPercentagesWithCalories(Integer userId, LocalDate date);


    void deleteUserMeal(Integer userId, LocalDate date);


    void deleteUserMealFoodByMealId(Integer mealId);

    int deleteUserMealById(@Param("id") Integer id);

    // 根据 userId, mealDate, mealTime 查找对应的 UserMeal 记录（用于删除时定位）
    UserMeal findMealByUserDateTime(@Param("userId") Integer userId,
                                    @Param("mealDate") LocalDate mealDate,
                                    @Param("mealTime") String mealTime);

    int updateUserMeal(UserMeal userMeal);


    List<UserMealFood> findFoodsByUserMealId(Integer userMealId);


    List<Map<String, Object>> getLast7DaysSummary(Integer userId);


    List<Map<String, Object>> getUserMealLastMonthByWeek(Integer userId);


    List<UserMeal> findMealsBetween(@Param("userId") Integer userId,
                                @Param("startDate") LocalDate startDate,
                                @Param("endDate") LocalDate endDate);
}
